//
//  TextFieldController.m
//  OCDemo
//
//  Created by zhumuzhi on 2021/7/14.
//

#import "TextFieldController.h"
#import "UITextField+Category.h"
#import "TextFieldView.h"

@interface TextFieldController ()<UITextFieldDelegate>

@property (nonatomic, strong) UIImageView   *icon;
@property (nonatomic, strong) TextFieldView *userAccount;
@property (nonatomic, strong) TextFieldView *passWord;

@end

@implementation TextFieldController

#pragma mark - LifeCycle

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.icon];
    [self.view addSubview:self.userAccount];
    [self.view addSubview:self.passWord];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(300.0f);
        make.centerX.equalTo(self.view);
        make.width.height.mas_equalTo(80.0f);
    }];
    
    [self.userAccount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icon.mas_bottom).offset(40.0);
        make.left.equalTo(self.view).offset(20.0f);
        make.right.equalTo(self.view).offset(-20.0f);
        make.height.mas_equalTo(50.0f);
    }];
    
    [self.passWord mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userAccount.mas_bottom).offset(40.0);
        make.left.right.equalTo(self.userAccount);
        make.height.mas_equalTo(50.0f);
    }];
    
}


#pragma mark - UITextFieldDelegate

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    return [textField utils_shouldChangeCharactersInRange:range replacementString:string];
}

#pragma mark - LazyGet

- (UIImageView *)icon {
    if (!_icon) {
        _icon = [[UIImageView alloc] init];
        _icon.layer.cornerRadius = 40.0f;
        _icon.backgroundColor = UIColorFromRGB(0xF6F6F6);
    }
    return _icon;
}

- (TextFieldView *)userAccount {
    if (!_userAccount) {
        _userAccount = [[TextFieldView alloc] init];
//        _userAccount.delegate = self;
//        _userAccount.utils_limitLegnth = 11;
//        _userAccount.utils_inputType = TextFieldInputTypePhoneNumber;
        _userAccount.backgroundColor = UIColorFromRGB(0xF6F6F6);
        _userAccount.layer.cornerRadius = 25.0f;
        _userAccount.layer.masksToBounds = YES;
//        UIView *left = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 20.0f, 50.0f)];
//        left.backgroundColor = UIColorFromRGB(0xF6F6F6);
//        _userAccount.leftViewMode = UITextFieldViewModeAlways;
//        _userAccount.leftView = left;
    }
    return _userAccount;
}

- (TextFieldView *)passWord {
    if (!_passWord) {
        _passWord = [[TextFieldView alloc] init];
        _passWord.rightViewMode = RightViewShowTypeAlways;
        _passWord.normalImage = [UIImage imageNamed:@"eye_close"];
        _passWord.highlightedImage = [UIImage imageNamed:@"eye"];
    }
    return _passWord;
    
}

@end
